package com.well.module.user.web;

import com.github.pagehelper.PageInfo;
import com.well.kernel.spring.web.ResponseData;
import com.well.kernel.spring.web.easyui.Datagrid;
import com.well.module.user.entity.UserInfo;
import com.well.module.user.service.UserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
* Copyright &copy; Well All rights reserved.
* Author:
* Date:2018-9-6
* Description:
*/

@Controller
@RequestMapping("/userInfo")
public class UserInfoController{

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 进入首页页面
     * @param modelMap
     * @return
     */
    @RequestMapping("/index")
    public ModelAndView index(ModelMap modelMap){
        // TODO:请输入页面
        return new ModelAndView("",modelMap);
    }

    /**
     * 获取 easyui 的 datagrid 分页数据
     * @param userInfo
     * @return
     */
    @RequestMapping("/datagrid")
    @ResponseBody
    public Datagrid<UserInfo> datagrid(UserInfo userInfo){
        PageInfo<UserInfo> pageInfo=userInfoService.selectPageInfo(userInfo);
        Datagrid<UserInfo> datagrid=new Datagrid<UserInfo>(pageInfo);
        return datagrid;
    }

    /**
     * 进入详情页面
     * @param id 主键
     * @param modelMap
     * @return
     */
    @RequestMapping("/detail")
    public ModelAndView detail(String id,ModelMap modelMap){
        UserInfo userInfo=userInfoService.select(id);
        modelMap.put("userInfo",userInfo);
        // TODO:请输入页面
        return new ModelAndView("",modelMap);
    }

    /**
     * 保存
     * @param userInfo
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResponseData save(UserInfo userInfo){
        int result=userInfoService.save(userInfo);
        if(result==0){
            return new ResponseData(false,"保存失败！");
        }
        return new ResponseData(true,"保存成功！");
    }

    /**
     * 逻辑删除
     * @param ids 多个主键，以","分割
     * @return
     */
    @RequestMapping("/logicalDelete")
    @ResponseBody
    public ResponseData logicalDelete(String ids){
        int result=userInfoService.logicalDelete(ids);
        if(result==0){
            return new ResponseData(false,"删除失败！");
        }
        return new ResponseData(true,"删除【"+result+"】条数据成功！");
    }

}
